<?php
echo $this->Session->flash();
App::Import('model', 'EvaluationAppraisal');
App::Import('model', 'TopographicMap');
$totalAreaAvaluos = 0;
$totalAreaPlano = 0;
?>

<div id="loading" style="display: none;">
<?php echo $html->image('loading.gif', array('border' => "0", 'align' => 'center')); ?>
</div>

<h1>PREDIOS PROYECTO <?php echo$cod; ?></h1>
<table  id="tabla" class="tabla" >
    <thead>
        <tr>
            <th>Código</th>
            <th>Nombre</th>
            <th colspan="4"></th>
        </tr>
    </thead>
    <tbody>
<?php foreach ($properties as $prop): ?>
            <tr>
                <td><?php
    //Busco el ultimo avaluo del predio y lo sumo a la variable $totalAreaAvaluos para luego mostrar el total del avaluo del proyecto.
    $avaluos = new EvaluationAppraisal();
    $avaluos->recursive = -1;
    $avaluo = $avaluos->find('first', array('conditions' => array('EvaluationAppraisal.property_id' => $prop['Property']['id']), 'order' => array('EvaluationAppraisal.id DESC'), 'fields' => array('EvaluationAppraisal.id', 'EvaluationAppraisal.area')));
    $totalAreaAvaluos += $avaluo['EvaluationAppraisal']['area'];
    //Busco el ultimo plano topografico y lo sumo a la variable $totalAreaPlano para luego mostrar el total del area de los planos del proyecto.
    $planos = new TopographicMap();
    $planos->recursive = -1;
    $plano = $planos->find('first', array('conditions' => array('TopographicMap.property_id' => $prop['Property']['id']), 'order' => array('TopographicMap.id DESC'), 'fields' => array('TopographicMap.id', 'TopographicMap.area')));
    $totalAreaPlano += $plano['TopographicMap']['area'];


    //imprimo el codigo del predio
    echo $prop['Property']['codigo']
    ?></td>
                <td><?php echo $prop['Property']['nombre'] ?></td>
                <td>
                    <br><br>
                    <?php echo $ajax->link('Filtro información', array('controller' => 'propertyReviews', 'action' => 'index', $prop['Property']['id']), array('class' => 'actions', 'update' => 'content')); ?>
                    <?php echo $ajax->link('Propietarios', array('controller' => 'owners', 'action' => 'owner_index', $prop['Property']['id']), array('class' => 'actions', 'update' => 'content', 'complete' => 'cargar()', 'indicator' => 'loading')); ?>
                    <?php echo $ajax->link('Plano topográfico', array('controller' => 'topographicMaps', 'action' => 'index', $prop['Property']['id']), array('class' => 'actions', 'update' => 'content', 'complete' => 'cargar()', 'indicator' => 'loading')); ?>
    <?php echo $ajax->link('Avalúo', array('controller' => 'EvaluationAppraisals', 'action' => 'index', $prop['Property']['id']), array('class' => 'actions', 'update' => 'content', 'complete' => 'cargar()', 'indicator' => 'loading')); ?>
                    <br><br>
                </td>
            </tr>
<?php endforeach; ?>
    </tbody>
</table>
<br>
<br>
<br>
<table class="tabla" >
    <thead>
        <tr>
            <th>Área total avaluos</th>
            <th>Área total de los planos topograficos</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td><?php echo $totalAreaAvaluos . ' (ha)' ?></td>
            <td><?php echo $totalAreaPlano . ' (ha)' ?></td>
        </tr>
    </tbody>
</table>